    package com.example.human_resource_management.controller;
    import com.example.human_resource_management.common.ResponseData;
    import com.example.human_resource_management.config.UserContext;
    import com.example.human_resource_management.config.UserContextUtils;
    import com.example.human_resource_management.entry.dto.EmployeeDto;
    import com.example.human_resource_management.entry.dto.EmployeeUpdateDto;
    import com.example.human_resource_management.entry.dto.PageDto;
    import com.example.human_resource_management.entry.dto.PagesDto;
    import com.example.human_resource_management.entry.po.Employee;
    import com.example.human_resource_management.service.EmployeeService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import java.util.List;

    @RestController
    @RequestMapping("/api/employee")
    public class EmployeeInfoController {

        @Autowired
        private EmployeeService employeeService;

        //测试方法
        @GetMapping("info")
        public ResponseData<Employee> getEmployeeInfo() {
            Long empId = UserContextUtils.getEmpId();
            if (empId != null) {
                Employee employee = employeeService.getEmployeeById(empId);
                if (employee != null) {
                    return ResponseData.ok(employee);
                }
            }
            return ResponseData.warn("未获取到员工信息");
        }

        //查询用户个人信息
        @GetMapping("select")
        public ResponseData<EmployeeDto> getEmployeeDetails() {
            Long empId = UserContextUtils.getEmpId();
            if (empId == null) {
                return ResponseData.warn("未获取到员工ID");
            }
            EmployeeDto dto = employeeService.getEmployeeDetails(empId);
            return dto != null ?
                    ResponseData.ok(dto) :
                    ResponseData.warn("员工信息不存在");
        }


        //用户修改个人信息
        @PostMapping("update")
        public ResponseData<String> updateBasicInfo(@RequestBody EmployeeUpdateDto dto) {
            Long empId = UserContextUtils.getEmpId();
            if (empId == null) {
                return ResponseData.warn("未获取到员工ID");
            }
            boolean success = employeeService.updateEmployeeFields(empId, dto.getName(),dto.getGender(), dto.getContact());
            return success ?
                    ResponseData.ok("修改成功") :
                    ResponseData.warn("修改失败");
        }

        //有图片
        @GetMapping("selectonlypages")
        public ResponseData<PageDto> get() {
            Long empId = UserContextUtils.getEmpId();
            if (empId == null) {
                return ResponseData.warn("未获取到员工ID");
            }
            PageDto dto = employeeService.get(empId);
            return dto != null ?
                    ResponseData.ok(dto) :
                    ResponseData.warn("员工信息不存在");
        }

        //只有图片
        @GetMapping("selectpage")
        public ResponseData<PagesDto> getpage() {
            Long empId = UserContextUtils.getEmpId();
            if (empId == null) {
                return ResponseData.warn("未获取到员工ID");
            }
            PagesDto dto = employeeService.getpage(empId);
            return dto != null ?
                    ResponseData.ok(dto) :
                    ResponseData.warn("员工信息不存在");
        }





        //管理员端
        // 查询所有员工信息
        @GetMapping("all")
        public ResponseData<List<EmployeeDto>> getAllEmployeeDetails() {
            List<EmployeeDto> employeeDtos = employeeService.selectAllEmployeeDetails();
            return ResponseData.ok(employeeDtos);
        }

        // 新增员工信息
        @PostMapping("add")
        public ResponseData<String> addEmployee(@RequestBody Employee employee) {
            boolean success = employeeService.insertEmployee(employee);
            return success ?
                    ResponseData.ok("新增员工成功") :
                    ResponseData.warn("新增员工失败");
        }

        // 修改员工信息
        @PutMapping("update")
        public ResponseData<String> updateEmployee(@RequestBody Employee employee) {
            boolean success = employeeService.updateEmployee(employee);
            return success ?
                    ResponseData.ok("修改员工信息成功") :
                    ResponseData.warn("修改员工信息失败");
        }

        // 删除员工信息
        @DeleteMapping("delete/{empId}")
        public ResponseData<String> deleteEmployee(@PathVariable Long empId) {
            boolean success = employeeService.deleteEmployee(empId);
            return success ?
                    ResponseData.ok("删除员工信息成功") :
                    ResponseData.warn("删除员工信息失败");
        }



    }
